package br.com.academia.controller;

import java.sql.SQLException;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import br.com.academia.DAO.DAOGenerico;
import br.com.academia.beans.Filial;
import br.com.academia.util.ConnectionFactory;

@Controller
public class FilialController {
	
	@RequestMapping("/inserirFilial")
	public String cadastrarFilial(Filial filial) throws SQLException, Exception {
		new DAOGenerico<Filial>(new ConnectionFactory().getConnection()).cadastrar(filial);
		return "redirect:frmFilial";
	}
	
	@RequestMapping("/alterarFilial")
	public String alterarEmpresa(Filial filial) throws SQLException, Exception {
		new DAOGenerico<Filial>(new ConnectionFactory().getConnection()).alterar(filial, "idFilial");
		return "forward:pesquisaAvancada?tipoPesquisa=filial";
	}
	
	@RequestMapping("/excluirFilial")
	public String excluirEmpresa(Filial filial) throws SQLException, Exception {
		new DAOGenerico<Filial>(new ConnectionFactory().getConnection()).excluir(filial, "idFilial");
		return "forward:pesquisaAvancada?tipoPesquisa=filial";
	}

}
